import { sys } from "cc";
import { DevConfig } from "../../scripts/managers/DevConfig";
import { timem } from "../../scripts/managers/TimeManager";
import { udm } from "../../scripts/managers/UserDataManager";
import { FlowStatus } from "./Enums";
import { lm } from "./LobbyManager";
import { game } from "cc";

export namespace develop_func {

    // debug切关卡
    export function debug_set_stage(stageNum: number) {
        udm.stageNum.value = stageNum;
        udm.save();
        // gm.loadGameCommand.execute();
        lm.flowStatus.value = FlowStatus.Lobby;
    }
    // debug 设置当前金币
    export function debug_set_coin(coin: number) {
        udm.coin.value = coin;
        udm.save();
    }
    // debug 设置心数量
    export function debug_set_heart(heartNum: number) {
        udm.heart.value.heart = heartNum;
        if (udm.heart.value.heart >= DevConfig.HEART_RESTORE_MAX_COUNT) {
            udm.heart.value.updateAt = timem.now();
        }
        udm.save();
        udm.heart.again();
    }
    // debug 设置noads状态 0|1
    export function debug_set_noads(value: number) {
        udm.noAds.value = value;
        udm.save();
    }
    export function debug_clear_all() {
        udm.clear();

        

        if (sys.isNative) {
            game.end();
        } else {
            window.location.reload(); // 刷新浏览器
        }
    }

    export function debug_set_savingpot_coin(value: number) {
        let oriCoin = udm.savingPot.value.coin;
        let tarCoin = value;
        if (tarCoin >= DevConfig.SAVING_POT.COIN_CAPACITY) {
            tarCoin = DevConfig.SAVING_POT.COIN_CAPACITY;
            if (oriCoin < DevConfig.SAVING_POT.COIN_CAPACITY) {
                udm.savingPot.value.expAt = timem.now() + DevConfig.SAVING_POT.EXP_SEC * 1000;
            }
        } else {
            udm.savingPot.value.expAt = null;
        }
        udm.savingPot.value.coin = tarCoin;
        udm.save();
    }

}